package RockBuddy;

/* Team Directories
 *
 * You are free to do whatever you want with this code. Frankly we don't give a damn.
 * 
 *  
 * Copyright GNU General Public License v3
 */

/**
 *
 * @author Gabriel
 */

import BuddyTemplate.QuestionFrame;
import BuddyTemplate.Question;
import BuddyTemplate.PictureFrame;
import BuddyTemplate.PictureChoiceFrame;
import BuddyTemplate.SaveGame;
import BuddyTemplate.QuestionLayerCollection;
import javax.swing.*;
import java.io.*;
import java.util.*;
        
public class Main implements StudyBuddy.RunnableBuddy{

    /**
     * @param args the command line arguments
     */
    
    String username;
    Integer thescore = new Integer(0);
    QuestionLayerCollection questions = new QuestionLayerCollection();
    
    public static void main(String[] args) {

    }
    
    public void run(){
        
        /* We Populate the QuestionCollection with questions*/
        
        Question<String, String> testquestion = new Question<String, String>();
        testquestion.setQuestion("What type of metamorphism is caused by high temperature and pressure that affects a large volume of crust?");
        testquestion.setDifficulty(3);
        testquestion.setChoice("hydrothermal metamorphism", false);
        testquestion.setChoice("regional metamorphism", true);
        testquestion.setChoice("contact metamorphism", false);
        testquestion.setChoice("cataclastic metamorphism", false);
        
        questions.addQuestion(testquestion);
        
        Question<String, String> testquestion2 = new Question<String, String>();
        testquestion2.setDifficulty(3);
        testquestion2.setQuestion("The Hawaiian Islands formed by");
        testquestion2.setChoice("convergence between the Pacific and Asian plates", false);
        testquestion2.setChoice("seafloor spreading at a mid-ocean ridge", false);
        testquestion2.setChoice("the Pacific plate traveling over a mantle hot spot", true);
        testquestion2.setChoice("a transform boundary at that location", false);
        
        questions.addQuestion(testquestion2);
        
        // We simply use this to demonstrate how a non-standard question is handled
        
        Question<Object, Object> testquestion3 = new Question<Object, Object>();
        testquestion3.setQuestion("Given the plate tectonic setting, volcanoes of the Cascade Range such as Mount St. Helens in Washington would most likely erupt");
        testquestion3.setDifficulty(3);
        testquestion3.setChoice("basalt magmas", false);
        testquestion3.setChoice("andesitic magmas", false);
        testquestion3.setChoice("all of the above", false);
        testquestion3.setChoice("may erupt rhyolitic or andesitic magma", true);
      //  testquestion3.setChoice(new ImageIcon(getClass().getResource( "/Picture/Clouds.jpg")), false);
        
        questions.addQuestion(testquestion3);
        
        
        
        
        Question<String, ImageIcon> testquestion5 = new Question<String, ImageIcon>();
        testquestion5.setQuestion("Which of these is a sedimentary rock?");
        testquestion5.setChoice(new ImageIcon(getClass().getResource( "/Picture/sedimentary rock.jpg")), true);
        testquestion5.setChoice(new ImageIcon(getClass().getResource( "/Picture/metamorphic rock.jpg")), false);
        testquestion5.setChoice(new ImageIcon(getClass().getResource( "/Picture/igneous rock.jpg")), false);
        testquestion5.setChoice(new ImageIcon(getClass().getResource( "/Picture/olivine mineral.jpg")), false);
        
       
        questions.addQuestion(testquestion5);
        
        
        Question<Object, Object> testquestion6 = new Question<Object, Object>();
        testquestion6.setDifficulty(3);
        testquestion6.setQuestion("Porphyritic texture forms from");
        testquestion6.setChoice("initial rapid cooling then slow cooling of magma", false);
        testquestion6.setChoice("initial slow cooling then rapid cooling of magma", true);
        testquestion6.setChoice("extremely rapid cooling of magma", false);
        testquestion6.setChoice("escape of gas bubbles during cooling of lava", false);
        questions.addQuestion(testquestion6);
        
        Question<Object, Object> testquestion7 = new Question<Object, Object>();
        testquestion7.setDifficulty(3);
        testquestion7.setQuestion("During crystallization of a basaltic magma _____________ is the first mineral to crystallize.");
        testquestion7.setChoice("pyroxene", false);
        testquestion7.setChoice("plagioclase", false);
        testquestion7.setChoice("quartz", false);
        testquestion7.setChoice("olivine", true);
        questions.addQuestion(testquestion7);
        
        Question<ImageIcon, String> testquestion8 = new Question<ImageIcon, String>();
        testquestion8.setDifficulty(2);
        testquestion8.setQuestion(new ImageIcon(getClass().getResource( "/Picture/igneous rock.jpg")));
        testquestion8.setChoice("sedimentary", false);
        testquestion8.setChoice("Igneous", true);
        testquestion8.setChoice("metamorphic ", false);
        testquestion8.setChoice("None of the above", false);
        questions.addQuestion(testquestion8);
        
        
       
        
        // This is the rather inelegant pieces of code which get the Ball Rolling
   
        // First we increase the state of the question - we request the nextquestion 
       
        Question thenextquestion = questions.nextQuestion();
        
        // Now depending on what question the first question is, we launch the appopriate window
        // Note that this same bit of code is also used in PictureFrame, PictureChoiceFrame, etc
        
        // We get the instance of the choice of the first method
        if(thenextquestion.choices.get(0) instanceof String && thenextquestion.getQuestion() instanceof String){
            QuestionFrame nextQuestion = new QuestionFrame(thescore, questions, thenextquestion);
            nextQuestion.setVisible(true);
        }
                
        else if(thenextquestion.choices.get(0) instanceof ImageIcon && thenextquestion.getQuestion() instanceof String){
            PictureFrame nextQuestion = new PictureFrame(thescore, questions, thenextquestion);
            nextQuestion.setVisible(true);
        }
                
        else if(thenextquestion.choices.get(0) instanceof String && thenextquestion.getQuestion() instanceof ImageIcon){
            PictureChoiceFrame nextQuestion = new PictureChoiceFrame(thescore, questions, thenextquestion);
            nextQuestion.setVisible(true);
        }
        
    }
    
    public String getName(){
        
        
        System.out.println("RRRRRRRRRRRRRRRRRRRRRRNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN" + " Rock Buddy");
        return "Rock Buddy";
        
    }
    
    public int getScore(){
       
        return SaveGame.score;
        
    }
    
    public void setLoginInfo(String theusername){
        
        username = theusername;
        
    }
    
    
    public Serializable getSavedGame(){
        
        return new SaveGame();
        
    }
    
    public void loadSavedGame(Serializable savegame){
        
        thescore = ((SaveGame)savegame).score;
        
    }
    
    

    

}
